local sk__zhonghou = fk.CreateSkill {

  name = "sk__zhonghou",

  tags = {},

}



sk__zhonghou:addEffect("viewas", {
  name = "sk__zhonghou",
  pattern = ".|.|.|.|.|basic",
  prompt = "#sk__zhonghou",
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("b")
    local names = player.getViewAsCardNames(player, sk__zhonghou.name, all_names)
    if #names == 0 then return false end
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = sk__zhonghou.name
    return card
  end,
  before_use = function(self, player, use)
    player.room:loseHp(player, 1, sk__zhonghou.name)
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(sk__zhonghou.name, Player.HistoryTurn) == 0
  end,
  enabled_at_response = function(self, player, response)
    return player:usedSkillTimes(sk__zhonghou.name, Player.HistoryTurn) == 0
  end,
})

sk__zhonghou:addEffect(fk.GameStart, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill("sk__zhonghou", true)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getOtherPlayers(player)) do
      room:handleAddLoseSkills(p, "sk__zhonghou&", nil, false, true)
    end
  end,
})

sk__zhonghou:addAcquireEffect(function(self, player, is_start)
  local room = player.room
  for _, p in ipairs(room:getOtherPlayers(player)) do
    room:handleAddLoseSkills(p, "sk__zhonghou&", nil, false, true)
  end
end)

sk__zhonghou:addLoseEffect(function(self, player, is_death)
  local room = player.room
  if not table.find(room:getOtherPlayers(player), function(p)
          return p:hasSkill("sk__zhonghou", true)
        end) then
     for _, p in ipairs(room:getOtherPlayers(player, true, true)) do
        room:handleAddLoseSkills(p, "-sk__zhonghou&", nil, false, true)
      end
  end
end)


sk__zhonghou:addEffect(fk.Deathed, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill("sk__zhonghou", true, true)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if not table.find(room:getOtherPlayers(player), function(p)
          return p:hasSkill("sk__zhonghou", true)
        end) then
      for _, p in ipairs(room:getOtherPlayers(player, true, true)) do
        room:handleAddLoseSkills(p, "-sk__zhonghou&", nil, false, true)
      end
    end
  end,
})

sk__zhonghou:addEffect(fk.DamageCaused, {
  name = "#sk__ganglie_trigger",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target and target == player and player:usedSkillTimes("sk__ganglie", Player.HistoryTurn) > 0 and
        not data.chain
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("sk__ganglie")
    player.room:notifySkillInvoked(player, "sk__ganglie", "offensive")
    data.damage = data.damage + 1
  end,
})

return sk__zhonghou
